# coding:utf-8
import re

from bson import ObjectId
from flask import request, jsonify
from flask_restful import Resource

from app import api
from service.video.Caption import srt2vtt, renderCaption


class VideoController(Resource):
    '''
    视频情感分析：贝叶斯
    1）
    2）分析,逐句分析，分数累加
    3）保存到数据库{keywords:[],sentiment:{pos:10,neg:20},wordFreq:[{'生活': 6}, {'一种': 5}, ]}
    4) 词云：http://localhost:8088/images/wordcloud
    '''

    def post(self):
        id = request.form.get('id')
        renderCaption(id)
class Srt2Vtt(Resource):
    '''
    将srt字幕文件转成vtt格式
    '''
    def post(self):
        text = request.form.get('text')
        data = srt2vtt(text)
        return {
            'code':0,
            'data':data
        }


api.add_resource(VideoController, '/sentiment/video')
api.add_resource(Srt2Vtt, '/srt2vtt')
